Installing Python and R/RStudio packages into user folders

(Draft; to do add screenshots)

Updated: 1-27-2023

  • This page contains instructions on how to install packages into an user’s folder.

  • Recall that on JupyterHub, each time one starts a server it uses a pre-set image. That is whatever changes one makes to the system files and folders will not be saved after the server shuts down.

Required items

We need to the followings.

  1. A running container.

  2. Terminal.

  3. RStudio for RStudio.

Python

The pip command works as follows.

pip <cmd> <option> <packages>

See the office page for details. Simply, add the --user option. That is to install jupyter-resource-usage so that it works each time you start your server, use the following.

pip install --user jupyter-resource-usage

RStudio

In RStudio, the command .libPaths() prints the list of package folders. On JupyterHub the default package folder is /opt/conda/lib/R/library. This is not a user folder, so after each restart any package installed will be lost. There are a few ways to remedy this by setting preferences and by adding it to the libPaths. One needs to create a dedicated folder in one’s private folder. In this example we use .r_user_lib for our user package folder. It can be changed to your liking.

To create a folder, execute the following command in the terminal.

mkdir ~/.r_uber_lib

In R/RStudio, execute the following to add this folder as your option.

.libPaths(new = c(unlist(strsplit("~/.r_user_lib", ":")), unlist(strsplit("/opt/conda/lib/R/library", ":"))))
.libPaths() # Check

Add the following to the file .Rprofile if you want this to happen each time you start R.

echo '.libPaths(new = c(unlist(strsplit("~/.r_user_lib", ":")), unlist(strsplit("/opt/conda/lib/R/library", ":"))))' >> ~/.Rprofile

If you want to revert this setting, simply delete the above line in .Rprofile.